if exists (select * from dbo.sysobjects where id = object_id(N'dbo.[IdentifyChangedData__{tableIdentifier}]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure dbo.[IdentifyChangedData__{tableIdentifier}]

exec('
CREATE PROCEDURE dbo.[IdentifyChangedData__{tableIdentifier}]
	@fromTranId bigint,
	@toTranId bigint
AS

SELECT 
	CTran.ID TransactionId
	,dbo.getChangeCommandType(D.ChangeTransactionId,I.ChangeTransactionId) CmdType
	,isnull(I.{sourceRowId},D.{sourceRowId}) SourceRowId
{columnsList}
FROM 
	dbo.[ChangeTransaction] CTran
	left join dbo.[{tableIdentifier}_deleted] D ON CTran.ID=D.ChangeTransactionID
	left join dbo.[{tableIdentifier}_inserted] I ON CTran.ID=I.ChangeTransactionID
where 
	(I.{sourceRowId}=D.{sourceRowId} or (I.{sourceRowId} is null and D.{sourceRowId} is not null) or (D.{sourceRowId} is null and I.{sourceRowId} is not null))
	and CTran.ID between @fromTranId and @toTranId
')
